package FrameWork;

import java.awt.Color;

import Announcements.Announcement;
import Main.SpaceGame;
import World.TileType;

public class Designation 
{
	int startX,startY,endX,endY,area;
	TileType type;
	SpaceGame main;
	
	public Designation(int startX,int startY,int endX,int endY,TileType type,SpaceGame main)
	{
		this.startX = startX;
		this.startY = startY;
		this.endX = endX;
		this.endY = endY;
		this.type = type;
		this.main = main;
		int length = Math.abs(startX - endX)+1;
		int height = Math.abs(startY - endY)+1;
		this.area = length * height;
		
		if (main.resources.getMetal() >= type.getMetalCost()*area)
		{
			if (main.resources.getBiomass() >= type.getBioCost()*area)
			{
				createTasks();
			}
			else
			{
				main.announcementManager.AddAnnouncement(new Announcement("You dont have enough biomatter! "+type+" tiles cost "+ type.getBioCost()+" biomatter each.", Color.red));
			}
		}
		else
		{
			main.announcementManager.AddAnnouncement(new Announcement("You dont have enough metal! "+type+" tiles cost "+ type.getMetalCost()+" metal each.", Color.red));
		}
		
	}
	
	public void createTasks()//For now im making it set tiles but eventually it will create jobs
	{
		main.resources.setMetal(main.resources.getMetal()-(type.getMetalCost()*area));
		main.resources.setBiomass(main.resources.getBiomass()-(type.getBioCost()*area)); //remove this if we never create tiles that cost bio-matter
		if (startY <= endY && startX <= endX)
		{
			for (int y = startY; y <= endY;y++)
			{
				for (int x = startX; x <= endX;x++)
				{
					main.resources.setMetal(main.resources.getMetal()+main.world.tiles[x][y].getType().getMetalCost());
					main.world.tiles[x][y].setType(type);
				}
			}
		}
	
		else if (startY >= endY && startX >= endX)
		{
			for (int y = startY; y >= endY;y--)
			{
				for (int x = startX; x >= endX;x--)
				{
					main.resources.setMetal(main.resources.getMetal()+main.world.tiles[x][y].getType().getMetalCost());
					main.world.tiles[x][y].setType(type);
				}
			}
		}
	
		else if (startY <= endY && startX >= endX)
		{
			for (int y = startY; y <= endY;y++)
			{
				for (int x = startX; x >= endX;x--)
				{
					main.resources.setMetal(main.resources.getMetal()+main.world.tiles[x][y].getType().getMetalCost());
					main.world.tiles[x][y].setType(type);
				}
			}
		}
	
		else if (startY >= endY && startX <= endX)
		{
			for (int y = startY; y >= endY;y--)
			{
				for (int x = startX; x <= endX;x++)
				{
					main.resources.setMetal(main.resources.getMetal()+main.world.tiles[x][y].getType().getMetalCost());
					main.world.tiles[x][y].setType(type);
				}
			}
		
		}
	}
}
